package org.zxp.designpattern.chain;

/**
 * @program: effectiveJava
 * @description: 抽象拦截器
 * @author: X-Pacific zhang
 * @create: 2019-08-29 15:21
 **/
public abstract class AbstractIntercept {
    private AbstractIntercept next;

    public void setNext(AbstractIntercept next){
        this.next = next;
    }

    public void Intercept(int k) throws Exception {
        if(!check(k)){
            throw new Exception(k+"被拦截了"+this.getClass().getName());
        }
        if(next != null){
            next.Intercept(k);
        }
    }

    /**
     * 抽象方法拦截，子类实现
     * @return
     */
    abstract  boolean check(int a);
}
